/*
 * 路由分发
 */
var router_config = {
	"/api/complex/Base": require("./router/complex/base"),
	"/api/complex/MoodsFactory": require("./router/complex/MoodsFactory"),
	"/api/complex/Menstruation": require("./router/complex/Menstruation"),
	"/api/complex/BodyData": require("./router/complex/BodyData"),
	"/api/complex/SleepData": require("./router/complex/SleepData"),
	"/api/complex/Memorandum": require("./router/complex/Memorandum"),
}

var _router_error = function(req, res) {
		res.send(404, "404 no find.");
		console.error("----404----");
		console.log(req.route);
		console.error("----404----");
	}
	// 打印数据库接口
var router = function(app) {
	for (var i in router_config) {
		(function(router_key) {
			var router_object = router_config[router_key];
			console.log("路由器初始化配置接口：", router_key);
			app.all(router_key, function(req, res) {
				res.header("Access-Control-Allow-Origin", "*");
				res.header("Access-Control-Allow-Headers", "X-Requested-With");
				var router_foo = router_object[req.method.toLowerCase()] || _router_error;
				router_foo.apply(app, arguments);
			})
		}(i));
	}
}
module.exports = router;